<template>
  <div class="item-one" ref="itemOne">
    <div class="title">
      <span>全部商户</span>
      <div>
        <!-- <el-button
          type="primary"
          v-if="userinfo.rolesId == '1' || userinfo.rolesId == '8'"
          @click="SplitAccountWindow()"
          >开通分账</el-button
        > -->
        <el-button
          type="primary"
          v-if="userinfo.rolesId == '1' || userinfo.rolesId == '8'"
          @click="setupshop()"
          >开通总分店</el-button
        >
        <el-button
          type="primary"
          v-if="userinfo.rolesId == '1' || userinfo.rolesId == '8'"
          @click="changeBDbtn()"
          >切换</el-button
        >
        <el-button type="primary" @click="addmerchants()">新增商户</el-button>
        <el-button type="primary" :disabled="exxxx" @click="merchantexcel"
          ><i class="el-icon-download"></i>导出</el-button
        >
        <el-button icon="el-icon-refresh" @click="refresh()"></el-button>
      </div>
    </div>
    <div class="container">
      <div class="screeningBox">
        <div class="leftBox">
          <div class="leftitem">
            <div class="block">
              <el-date-picker
                v-model="date"
                type="datetimerange"
                value-format="yyyy-MM-dd HH:mm:ss"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
                style="width: 60%"
              ></el-date-picker>
            </div>
          </div>
          <div class="leftitem" v-if="userinfo.rolesId != 4">
            <el-form ref="conditions" :model="conditions">
              <el-select
                v-if="
                  userinfo.rolesId == 1 ||
                  userinfo.rolesId == 8 ||
                  userinfo.rolesId == 9
                "
                v-model="conditions.servicelevel"
                placeholder="服务商级别"
                @change="servicelevel"
                style="width: 29%"
              >
                <el-option
                  keys="1"
                  label="一级服务商"
                  value="1"
                  style="width: 100%"
                ></el-option>
                <el-option
                  keys="2"
                  label="二级服务商"
                  value="2"
                  style="width: 100%"
                ></el-option>
              </el-select>

              <el-autocomplete
                v-if="
                  userinfo.rolesId == 1 ||
                  userinfo.rolesId == 8 ||
                  userinfo.rolesId == 2 ||
                  userinfo.rolesId == 9
                "
                v-model.trim="conditions.servicename"
                :fetch-suggestions="querySearch"
                placeholder="服务商名称"
                @select="serviceid"
                style="width: 29%"
              ></el-autocomplete>
              <el-autocomplete
                v-if="userinfo.rolesId != 5"
                class="BDname"
                v-model.trim="conditions.BDname"
                :fetch-suggestions="BDname"
                placeholder="业务经理"
                @select="BDid"
                style="width: 29%"
              ></el-autocomplete>
            </el-form>
          </div>
          <div class="leftitem">
            <el-form ref="conditions" :model="conditions" label-width="80px">
              <el-select
                v-model="conditions.merchantsstate"
                placeholder="商户状态"
                style="width: 29%"
              >
                <el-option keys="3" label="正常" value="0"></el-option>
                <el-option keys="4" label="停用" value="98"></el-option>
                <el-option keys="4" label="审核中" value="1"></el-option>
                <el-option keys="4" label="驳回" value="9"></el-option>
              </el-select>
              <el-input
                class="merchants"
                v-model.trim="conditions.merchantsno"
                @keyup.enter.native="soso"
                placeholder="商户号/商户名称"
                style="width: 29%"
              ></el-input>
              <el-input
                class="merchants"
                v-model.trim="conditions.mchId"
                @keyup.enter.native="soso"
                placeholder="渠道商户号"
                style="width: 29%"
              ></el-input>
            </el-form>
          </div>
        </div>
        <div class="rightBox">
          <div class="rightitem">
            <el-form label-width="80px">
              <el-select
                v-model="channelType"
                placeholder="通道类型"
                style="width: 25%"
              >
                <el-option
                  v-for="(value, index) in channelTypeList"
                  :key="index"
                  :label="value.options"
                  :value="value.code"
                ></el-option>
              </el-select>
              <el-select
                v-model="payType"
                placeholder="支付方式"
                style="width: 25%"
              >
                <el-option keys="300" label="支付宝" :value="300"></el-option>
                <el-option keys="400" label="微信" :value="400"></el-option>
                <el-option keys="600" label="云闪付" :value="600"></el-option>
                <el-option keys="700" label="翼支付" :value="700"></el-option>
                <el-option
                  keys="800"
                  label="数字人民币"
                  :value="800"
                ></el-option>
                <el-option keys="900" label="龙支付" :value="900"></el-option>
              </el-select>
              <el-select
                v-model="merchantMode"
                placeholder="经营模式"
                style="width: 20%"
              >
                <el-option keys="mode0" label="普通模式" :value="0"></el-option>
                <el-option
                  keys="mode1"
                  label="总分店模式"
                  :value="1"
                ></el-option>
              </el-select>
              <el-select
                v-model="SplitAccountMode"
                placeholder="商户分账"
                style="width: 20%"
              >
                <el-option
                  v-for="item in SplitAccountModeoptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form>
          </div>
          <!-- <div class="rightitem">
            <el-form label-width="80px">
           <el-select
                v-model="wx1code"
                placeholder="行业"
                @change="wx2fun"
                style="width: 29%"
              >
                <el-option
                  v-for="(value, index) in wx1arr"
                  :key="index"
                  :label="value.mcc1Name"
                  :value="value.id"
                  style="width: 100%"
                ></el-option>
              </el-select>
              <el-select
                v-model="conditions.wx1s"
                placeholder="细分行业"
                @change="wx3fun"
                style="width: 29%"
              >
                <el-option
                  v-for="(value, index) in wx2arr"
                  :key="index"
                  :value="value.id"
                  :label="value.mcc2Name"
                  style="width: 100%"
                ></el-option>
              </el-select> 
              <el-input
                v-model.trim="conditions.contactName"
                @keyup.enter.native="soso"
                placeholder="商户联系人"
                style="width: 29%"
              ></el-input>
            </el-form>
          </div> -->
          <div class="rightitem">
            <el-form ref="conditions" :model="conditions" label-width="80px">
              <el-select
                v-model="conditions.province"
                placeholder="所在省"
                @change="city"
              >
                <el-option
                  v-for="(item, index) in provincearr"
                  :key="index"
                  :label="item.provinceName"
                  :value="item.id"
                  :codeid="item.id"
                ></el-option>
              </el-select>
              <el-select
                v-model="conditions.city"
                placeholder="所在市"
                @change="city2"
              >
                <el-option
                  v-for="(value, index) in cityarr"
                  :key="index"
                  :label="value.cityName"
                  :value="value.id"
                ></el-option>
              </el-select>
              <el-input
                v-model.trim="conditions.contactName"
                @keyup.enter.native="soso"
                placeholder="商户联系人"
                style="width: 29%"
              ></el-input>
            </el-form>
          </div>
          <div class="rightitem">
            <el-form
              v-if="
                userinfo.rolesId == 1 ||
                userinfo.rolesId == 2 ||
                userinfo.rolesId == 8 ||
                userinfo.rolesId == 9
              "
            >
              <el-autocomplete
                v-model.trim="tagname"
                :fetch-suggestions="querySearch_tag"
                @select="serviceid_tag"
                placeholder="标签名称"
                :trigger-on-focus="false"
                style="width: 30%"
              ></el-autocomplete>
              <el-input
                v-model="inKeyWards"
                placeholder="银行会员号/账户名"
                style="width: 30%"
              ></el-input>
            </el-form>
          </div>
          <div class="rightitem">
            <el-button icon="el-icon-search" type="primary" @click="soso"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" type="primary" @click="reset"
              >重置</el-button
            >
          </div>
        </div>
      </div>
      <div class="statistical">
        <div class="statisticalitem">
          <div>总商户数</div>
          <div>
            <span class="red">{{ merchantsinfo.total }}</span> 家
          </div>
        </div>
        <div class="statisticalitem">
          <div>动销商户数</div>
          <div>
            <span class="red">{{ merchantsinfo.active }}</span> 家
          </div>
        </div>
      </div>
      <div class="tableBox">
        <el-table
          ref="multipleTable"
          :data="merchantarr"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange"
          stripe
          :header-cell-style="tableHeaderColor"
          v-loading="loading"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column
            align="center"
            type="index"
            label="序号"
          ></el-table-column>
          <el-table-column
            label="商户号?商户简称/商户名"
            width="240"
            align="center"
            :render-header="renderheader"
          >
            <template slot-scope="scope">
              <div class="position" v-if="scope.row.pid == '-1'">总</div>
              <div
                class="position greens"
                v-if="scope.row.pid != '-1' && scope.row.pid"
              >
                分
              </div>
              <div>{{ scope.row.merchantNo }}</div>
              <div class="merchantNameStyle">
                {{ scope.row.merchantShortName }}/{{ scope.row.merchantName }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="所在省?所在市"
            width="80"
            align="center"
            :render-header="renderheader"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.merchantProvince }}</div>
              <div>{{ scope.row.merchantCity }}</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="name"
            label="业务经理?服务商"
            align="center"
            :render-header="renderheader"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.bdName }}</div>
              <div>{{ scope.row.agent2Name }}</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="address"
            label="使用通道"
            align="center"
            :render-header="renderheader"
          >
            <template slot-scope="scope">
              <div>
                微信-{{ scope.row.wxChannelName }}
                <span v-if="scope.row.wxChannelStatus == 0" class="hui"
                  >-审核中</span
                >
                <span v-if="scope.row.wxChannelStatus == 1" class="green"
                  >-通过</span
                >
                <span v-if="scope.row.wxChannelStatus == 2" class="red"
                  >-驳回</span
                >
                <span v-if="scope.row.wxChannelStatus == 3" class="blue"
                  >-预审核通过</span
                >
                <span v-if="scope.row.wxChannelStatus == 4" style="color:#E6A23C;">-待提交</span>
              </div>
              <div>
                支付宝-{{ scope.row.aliChannelName }}
                <span v-if="scope.row.aliChannelStatus == 0" class="hui"
                  >-审核中</span
                >
                <span v-if="scope.row.aliChannelStatus == 1" class="green"
                  >-通过</span
                >
                <span v-if="scope.row.aliChannelStatus == 2" class="red"
                  >-驳回</span
                >
                <span v-if="scope.row.aliChannelStatus == 3" class="blue"
                  >-预审核通过</span
                >
                <span v-if="scope.row.aliChannelStatus == 4" style="color:#E6A23C;">-待提交</span>
              </div>
              <div v-if="scope.row.uniChannelId !== null">
                云闪付-{{ scope.row.uniChannelName }}
                <span v-if="scope.row.uniChannelStatus == 0" class="hui"
                  >-审核中</span
                >
                <span v-if="scope.row.uniChannelStatus == 1" class="green"
                  >-通过</span
                >
                <span v-if="scope.row.uniChannelStatus == 2" class="red"
                  >-驳回</span
                >
                <span v-if="scope.row.uniChannelStatus == 3" class="blue"
                  >-预审核通过</span
                >
                <span v-if="scope.row.uniChannelStatus == 4" style="color:#E6A23C;">-待提交</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="merchantMccName"
            label="所属行业"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="createTime"
            label="创建时间"
            align="center"
          ></el-table-column>
          <el-table-column label="商户状态" width="80" align="center">
            <template slot-scope="scope">
              <div
                class="green"
                v-if="scope.row.status == 0 || scope.row.status == 10"
              >
                正常<span v-if="scope.row.reviewedReason"></span>
              </div>
              <div class="hui" v-if="scope.row.status == 1">运营审核中</div>
              <div class="red" v-if="scope.row.status == 9">运营驳回</div>
              <div class="red" v-if="scope.row.status == 98">停用</div>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            align="center"
            label="操作"
            width="140"
          >
            <template slot-scope="scope">
              <el-button
                type="text"
                size="small"
                @click="joinmerchantsinfo(scope.row)"
                :valu="scope.row.merchantNo"
                >详情</el-button>
              <el-button
                v-if="scope.row.pid != '-1'"
                type="text"
                size="small"
                @click="addshop(scope.row.merchantShortName, scope.row.id)"
                >新增门店</el-button
              >
              <!-- <el-button
                v-if="scope.row.pid == '-1'"
                type="text"
                size="small"
                @click="chainclose(scope.row.id)"
              >关闭总门店</el-button> -->
              <el-button
                v-if="scope.row.status == 0 || scope.row.status == 10"
                type="text"
                size="small"
                @click="blockups(scope.row.id)"
                >停用</el-button
              >
              <el-button
                type="text"
                size="small"
                v-if="scope.row.status == 98"
                @click="merchantenable(scope.row.id)"
                >启用</el-button
              >
              <el-button
                type="text"
                size="small"
                v-if="oeminfo.delMer != 0 && userinfo.rolesId == '1'"
                @click="merchantremove(scope.row.id)"
                >注销</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination">
          <el-pagination
            background
            @current-change="handleCurrentChange"
            @size-change="sizechange"
            :current-page.sync="cur_page"
            :page-size="30"
            layout="total, sizes, prev, pager, next, jumper"
            :total="combined"
          ></el-pagination>
        </div>
      </div>
      <br />
      <br />
      <!-- 新增门店 -->
      <el-dialog
        title="新增门店"
        :visible.sync="visible"
        width="60%"
        :close-on-click-modal="false"
      >
        <el-form
          :model="addmendian"
          status-icon
          ref="addmendian"
          label-width="125px"
          class="demo-dynamic store-detail"
        >
          <div class="detail-item">
            <el-form-item label="所属商户">{{ shopname }}</el-form-item>
            <el-form-item :required="true" label="门店名称">
              <el-input
                class="store-input"
                type="text"
                v-model.trim="addmendian.name"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item :required="true" label="门店电话">
              <el-input
                class="store-input"
                type="text"
                v-model.trim="addmendian.phone"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item :required="true" label="门店地址">
              <el-input
                class="store-input"
                type="text"
                v-model.trim="addmendian.address"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item :required="true" label="联系人">
              <el-input
                class="store-input"
                type="text"
                v-model.trim="addmendian.contact"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item :required="true" label="联系人手机号">
              <el-input
                class="store-input"
                type="text"
                v-model.trim="addmendian.contactphone"
                autocomplete="off"
              ></el-input>
            </el-form-item>

            <el-form-item label="优惠券撤销权限">
              <!-- <el-input type="text" v-model.trim="chengeqx" autocomplete="off"></el-input> -->
              <el-switch
                v-model="chengeqx"
                active-color="#13ce66"
                autocomplete="off"
                active-value="1"
                inactive-value="0"
                inactive-color="#ff4949"
              >
              </el-switch>
            </el-form-item>

            <el-form-item label="门店类型描述">
              <el-input
                class="store-input"
                type="text"
                v-model.trim="addmendian.udfType"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="入账账户名">
              <el-input
                class="store-input"
                type="text"
                v-model.trim="addmendian.udfAccount"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="门店别名">
              <el-input
                class="store-input"
                type="text"
                v-model.trim="addmendian.alias"
                autocomplete="off"
              ></el-input>
            </el-form-item>
          </div>

          <div class="detail-item">
            <el-form-item label="微信子商户号">
              <el-input
                class="store-input"
                type="text"
                v-model.trim="addmendian.wxMchId"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="微信子商户appid">
              <el-input
                class="store-input"
                type="text"
                v-model.trim="addmendian.wxAppid"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="微信订单优惠标记">
              <el-input
                class="store-input"
                type="text"
                v-model.trim="addmendian.wxGoodsTag"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="银联子商户号">
              <el-input
                class="store-input"
                type="text"
                v-model.trim="addmendian.mchUniNo"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="银联终端号">
              <el-input
                class="store-input"
                type="text"
                v-model.trim="addmendian.bank"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="支付宝门店ID">
              <el-input
                class="store-input"
                type="text"
                v-model.trim="addmendian.aliShopId"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="支付宝授权令牌">
              <el-input
                class="store-input"
                type="text"
                v-model.trim="addmendian.aliSpmerToken"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="龙支付柜台号">
              <el-input
                class="store-input"
                type="text"
                v-model.trim="addmendian.longpayPostId"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="龙支付公钥">
              <el-input
                class="store-input"
                type="textarea"
                rows="2"
                v-model.trim="addmendian.longpayPublicKey"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="数币终端号">
              <el-input
                class="store-input"
                type="text"
                v-model.trim="addmendian.ecnyTermId"
                autocomplete="off"
              ></el-input>
            </el-form-item>
          </div>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="visible = false">取消</el-button>
          <!-- @click="visible = false" -->
          <el-button type="primary" @click="addshopfun()">确定</el-button>
        </span>
      </el-dialog>

      <!-- 切换业务经理 -->
      <el-dialog
        v-dialogDrag
        title="切换业务经理"
        :visible.sync="changeBD"
        width="45%"
        :close-on-click-modal="false"
      >
        <el-form
          :model="addmendian"
          status-icon
          ref="addmendian"
          label-width="110px"
          class="demo-dynamic"
        >
          <el-form-item label="商户名称:">
            <span v-for="(item, index) in multipleSelection" :key="index"
              >{{ item.merchantName }}，</span
            >
          </el-form-item>
          <el-form-item label="业务经理:">
            <el-autocomplete
              v-if="userinfo.rolesId == 1 || userinfo.rolesId == 8"
              class="wid100"
              v-model="changeBDdata.agent1"
              :fetch-suggestions="querySearch1"
              placeholder="请选择一级服务商"
              @select="serviceid1"
            ></el-autocomplete>
            <el-autocomplete
              v-if="
                userinfo.rolesId == 1 ||
                userinfo.rolesId == 8 ||
                userinfo.rolesId == 2
              "
              class="wid100"
              v-model="changeBDdata.agent2"
              :fetch-suggestions="querySearch2"
              placeholder="请选择二级服务商"
              @select="serviceid2"
            ></el-autocomplete>
            <el-autocomplete
              v-if="
                userinfo.rolesId != 4 &&
                userinfo.rolesId != 5 &&
                userinfo.rolesId != 6
              "
              class="wid100"
              v-model="changeBDdata.BDname"
              :fetch-suggestions="BDname"
              placeholder="业务经理"
              @select="BDid1"
            ></el-autocomplete>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="changeBD = false">取消</el-button>
          <!-- @click="visible = false" -->
          <el-button type="primary" @click="changeBDok()">确定</el-button>
        </span>
      </el-dialog>

      <!-- 总分店模式配置 -->
      <el-dialog
        v-dialogDrag
        title="总分店模式配置"
        :visible.sync="visible1"
        width="45%"
        :close-on-click-modal="false"
      >
        <el-form
          :model="setupshops"
          status-icon
          ref="setupshops"
          label-width="110px"
          class="demo-dynamic"
        >
          <el-form-item label="角色选择">
            <el-radio-group v-model="setupshops.type" @change="setupshopstype">
              <el-radio label="-1">总店</el-radio>
              <el-radio label="2">分店</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="总店模式" v-if="setupshops.type == -1">
            <el-radio-group v-model="setupshops.polling">
              <el-radio label="0">顺序模式</el-radio>
              <el-radio label="1">随机模式</el-radio>
              <el-radio label="2">加权模式</el-radio>
              <el-radio label="3">平滑加权模式</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="选择总店" v-if="setupshops.type == 2">
            <!-- <el-input :disabled="(setupshops.type == 1)?true:false" type="text" v-model.trim="addmendian.phone" autocomplete="off"></el-input> -->
            <el-autocomplete
              v-if="
                userinfo.rolesId == 1 ||
                userinfo.rolesId == 8 ||
                userinfo.rolesId == 2 ||
                userinfo.rolesId == 9
              "
              class="servicename"
              v-model.trim="setupshops.dianming"
              :fetch-suggestions="querySearch3"
              placeholder="选择总店"
              @select="dianming"
            ></el-autocomplete>
          </el-form-item>
          <el-form-item label="选择营业时间" v-if="setupshops.type == 2">
            <el-time-picker
              v-model="setupshops.openTime"
              value-format="HH:mm"
              format="HH:mm"
              placeholder="开始时间"
            >
            </el-time-picker
            >至
            <el-time-picker
              v-model="setupshops.closeTime"
              value-format="HH:mm"
              format="HH:mm"
              placeholder="结束时间"
            >
            </el-time-picker>
          </el-form-item>
          <el-form-item label="是否限额" v-if="setupshops.type == 2">
            <el-radio-group
              v-model="setupshops.permissions"
              :disabled="setupshops.type == 1 ? true : false"
            >
              <el-radio label="1">是</el-radio>
              <el-radio label="2">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="限额额度" v-if="setupshops.type == 2">
            <el-input
              style="width: 80%"
              placeholder="请输入限额额度"
              :disabled="setupshops.permissions == 2 ? true : false"
              type="text"
              v-model.trim="setupshops.lines"
              autocomplete="off"
            ></el-input
            >元
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="visible1 = false">取消</el-button>
          <!-- @click="visible = false" -->
          <el-button type="primary" @click="setupshopok()">确定</el-button>
        </span>
      </el-dialog>
      <!-- 开通分账弹窗 -->
      <el-dialog
        v-dialogDrag
        title="开通分账"
        :visible.sync="SplitAccountState"
        width="45%"
        :close-on-click-modal="false"
        :before-close="closeSplitAccount"
      >
        <el-form
          :model="SplitAccount"
          status-icon
          ref="SplitAccount"
          label-width="110px"
          class="demo-dynamic"
        >
          <el-form-item label="角色选择">
            <el-radio-group
              v-model="SplitAccount.flag"
              @change="SplitAccountType"
            >
              <el-radio label="1">分出方商户</el-radio>
              <el-radio label="2">接收方商户</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="选择交易商户" v-if="SplitAccount.flag == 2">
            <el-autocomplete
              v-if="
                userinfo.rolesId == 1 ||
                userinfo.rolesId == 8 ||
                userinfo.rolesId == 2 ||
                userinfo.rolesId == 9
              "
              class="servicename"
              v-model.trim="SplitAccount.dianming2"
              :fetch-suggestions="TransactionMerchantList"
              placeholder="选择交易商户"
              @select="dianming2"
            ></el-autocomplete>
          </el-form-item>

          <el-form-item label="选择分账通道">
            <!-- <el-form-item label="选择分账通道" v-if="SplitAccount.flag == 2"> -->
            <el-autocomplete
              v-if="
                userinfo.rolesId == 1 ||
                userinfo.rolesId == 8 ||
                userinfo.rolesId == 2 ||
                userinfo.rolesId == 9
              "
              class="servicename"
              v-model.trim="SplitAccount.dianming3"
              :fetch-suggestions="ListDistributionChannels"
              placeholder="选择分账通道"
              @select="dianming3"
            ></el-autocomplete>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="closeSplitAccount()">取消</el-button>
          <el-button type="primary" @click="splitAccountOk()">确定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import {
  APIallTransactionMerchantlist,
  APIDistributionChannelsList,
  APIActivateSplitAccountMerchants,
  getservice,
  getBD,
  merchantlist,
  getActiveCount,
  addshop,
  blockup,
  merchantremove,
  merchantenable,
  merchanttransfer,
  myMerchantExcel,
  getlabelTagList,
  getDimensionTagList,
  getChannelList,
  allmerchantlist,
  chainopen,
  chainclose,
  arealist,
  mcclist,
} from "@/api/api";
import axios from "axios";
import bus from "../common/bus";
export default {
  name: "baseform",
  data: function () {
    return {
      SplitAccountModeoptions: [
        {
          value: "0",
          label: "不分账",
        },
        {
          value: "1",
          label: "分账",
        },
      ],
      SplitAccountMode: "", //商户分账模式
      SplitAccountState: false,
      chengeqx: 0,
      oeminfo: {},
      tagsList: [],
      tableData: [],
      cur_page: 1,
      cur_size: 30,
      multipleSelection: [],
      visible: false,
      loading: true,
      changeBD: false,
      exxxx: false,
      visible1: false,
      setupshops: {
        type: "-1",
        openTime: "",
        closeTime: "",
        permissions: "",
        lines: "",
        pid: "-1",
        polling: "0",
      },
      SplitAccount: {
        flag: "1", //1:交易商户开通分账 2: 给交易商户开通分账商户
        ...this.defaultSplitAccountData(),
      },
      servicearr: [],
      servicearr1: [],
      BDarr: [],
      provincearr: [],
      cityarr: [],
      wx1arr: [],
      ids: [],
      wx1code: "",
      wx2arr: "",
      merchantarr: [],
      combined: 30,
      pageCount: "",
      merchantsinfo: "",
      shopname: "",
      shopid: "",
      date: "",
      merarr: [],
      TransactionMerchantarr: [], //交易商户
      DistributionChannelsarr: [], //分账通道
      addmendian: {
        name: "",
        phone: "",
        address: "",
        contact: "",
        contactphone: "",
        mchUniNo: "",
        wxMchId: "",
        wxAppid: "",
        udfType: "",
        udfAccount: "",
        bank: "",
        aliShopId: "",
        aliSpmerToken: "",
        alias: "",
        wxGoodsTag: "",
        ecnyTermId: "",
      },
      changeBDdata: {
        agent1: "",
        agent2: "",
        BDname: "",
      },
      conditions: {
        servicelevel: "",
        servicename: "",
        BDname: "",
        merchantsstate: "",
        merchantsno: "",
        province: "",
        provincecode: "",
        city: "",
        stardate: "",
        enddate: "",
        serviceid: "",
        BDid: "",
        wx1s: "",
        mchId: "",
      },
      userinfo: {},
      payType: "", //支付方式
      channelType: "", //通道类型
      channelTypeList: [],
      dimension: "", //选择维度
      tagname: "", //标签名
      label_all: [], //标签模糊查询
      tagId: "",
      merchantMode: "", //经营模式
    };
  },
  created() {
    this.userinfo = JSON.parse(sessionStorage.getItem("userInfo"));
    // console.log(this.userinfo);
    if (sessionStorage.getItem("oeminfo") != "null") {
      this.oeminfo = JSON.parse(sessionStorage.getItem("oeminfo"));
    }

    // 根据角色区别模糊搜索内容
    if (this.userinfo.rolesId == 2 || this.userinfo.rolesId == 3) {
      getservice({
        type: 2,
        parentid: this.userinfo.fid,
      }).then((res) => {
        // console.log(res);
        for (var i = 0; i < res.data.rows.length; i++) {
          this.servicearr.push({
            value: res.data.rows[i].agentname,
            id: res.data.rows[i].id,
          });
        }
      });
      this.getBD(this.userinfo.fid);
    } else {
      this.getBD();
    }
    this.province();
    this.wx1();
    this.merchantlist();
    if (this.userinfo.rolesId == 2) {
      this.conditions.servicelevel == 2;
    } else if (this.userinfo.rolesId == 1) {
      this.conditions.servicelevel == 1;
    }
    this.getChannelList();
    // let _this = this
    //  bus.$on('tags', msg => {
    //    console.log(msg)
    //    _this.tagsList = msg
    // })
  },
  methods: {
    cleanSplitAccountData(defineLabelValue = "1") {
      this.SplitAccount = {
        flag: defineLabelValue,
        ...this.defaultSplitAccountData(),
      };
    },
    defaultSplitAccountData() {
      return {
        merchantId: "", //分账商户id
        tradeMerchantId: "", //交易商户id
        merchantNo: "", //分账商户号
        channelId: "", //通道id
        channelType: "", //通道类型
        channelName: "", //通道名称
      };
    },
    defaulMerchantListData(res) {
      if (res.data instanceof Array) {
        this.merchantarr = res.data;
      } else {
        this.merchantarr = [];
      }

      if (res.pageInfo) {
        this.combined = res.pageInfo.recordCount;
        this.pageCount = res.pageInfo.pageCount;
      } else {
        this.combined = 0;
        this.pageCount = 0;
      }
    },
    //修改thead 背景色
    tableHeaderColor({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background-color: #F0F0F0;font-weight: 500;font-size:14px;color:#000;";
      }
    },
    // 刷新
    refresh() {
      // this.$router.replace({
      //   path: "/refresh",
      //   query: {
      //     t: Date.now()
      //   }
      // });
      this.loading = true;
      this.merchantlist(this.conditions.servicelevel);
    },
    renderheader(h, { column, $index }) {
      return h("span", {}, [
        h("span", {}, column.label.split("?")[0]),
        h("br"),
        h("span", {}, column.label.split("?")[1]),
      ]);
    },
    // 分页导航
    handleCurrentChange(val) {
      this.cur_page = val;
      this.merchantlist(this.conditions.servicelevel);
      this.$nextTick(() => {
        document.querySelectorAll(".content")[0].scrollTop = "0";
      });
    },
    // 分页数量
    sizechange(val) {
      this.cur_size = val;
      this.merchantlist(this.conditions.servicelevel);
      this.$nextTick(() => {
        document.querySelectorAll(".content")[0].scrollTop = "0";
      });
    },
    //多选框
    handleSelectionChange(val) {
      // console.log("多选框", val);
      this.multipleSelection = val;
    },
    joinmerchantsinfo(val) {
      // console.log(val.merchantName);
      this.$router.push({
        path: "/merchantsinfo",
      });
      sessionStorage.setItem("merchants_id", JSON.stringify(val.id));
      sessionStorage.setItem(
        "merchants_merchantName",
        JSON.stringify(val.merchantName)
      );
    },
    //  重置
    reset() {
      this.SplitAccountMode = "";
      this.date = "";
      this.conditions.servicelevel = "";
      this.conditions.servicename = "";
      this.conditions.BDname = "";
      this.conditions.merchantsstate = "";
      this.conditions.merchantsno = "";
      this.conditions.mccId = "";
      this.conditions.areaId = "";
      this.conditions.province = "";
      this.conditions.city = "";
      this.conditions.wx1s = "";
      this.conditions.stardate = "";
      this.conditions.enddate = "";
      this.conditions.serviceid = "";
      this.conditions.BDid = "";
      this.conditions.contactName = "";
      this.wx1code = "";
      this.cur_page = 1;
      this.dimension = "";
      this.tagname = "";
      this.tagId = "";
      this.payType = "";
      this.channelType = "";
      this.conditions.mchId = "";
      this.merchantMode = "";
    },
    // 搜索
    soso() {
      // console.log("商户分账", this.SplitAccountMode);
      if (
        this.date == null ||
        this.date.length == 0 ||
        this.date == undefined
      ) {
        this.date = [];
      }
      this.cur_page = 1;
      if (this.channelType !== "" && this.payType == "") {
        this.$message.error("请先选择支付方式");
        return false;
      }
      if (this.payType !== "" && this.channelType == "") {
        this.$message.error("请选择通道类型");
        return false;
      }
      this.loading = true;
      if (!this.conditions.servicename) {
        this.conditions.serviceid = "";
      }
      if (!this.conditions.BDname) {
        this.conditions.BDid = "";
      }
      if (this.conditions.servicelevel == 1) {
        this.merchantlist("1");
      } else if (this.conditions.servicelevel == 2) {
        this.merchantlist("2");
      } else {
        this.merchantlist("2");
      }
    },
    getChannelList() {
      getChannelList({}).then((res) => {
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else if (res.code == 200) {
          this.channelTypeList = res.data;
        } else if (res.code == 500) {
          this.$message.error(res.message);
        }
      });
    },
    // 服务商名称
    querySearch(queryString, cb) {
      let servicearr = this.servicearr;
      let results = queryString
        ? servicearr.filter(this.createFilter(queryString))
        : servicearr;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    // 切换BD服务商名称
    querySearch1(queryString, cb) {
      let servicearr = this.servicearr1;
      let results = queryString
        ? servicearr.filter(this.createFilter(queryString))
        : servicearr;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    // 二级服务商
    querySearch2(queryString, cb) {
      let servicearr = this.servicearr2;
      let results = queryString
        ? servicearr.filter(this.createFilter(queryString))
        : servicearr;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    //选择交易商户
    TransactionMerchantList(queryString, cb) {
      let TransactionMerchantarr = this.TransactionMerchantarr;
      let results = queryString
        ? TransactionMerchantarr.filter(this.createFilter(queryString))
        : TransactionMerchantarr;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    //选择分账通道
    ListDistributionChannels(queryString, cb) {
      let DistributionChannelsarr = this.DistributionChannelsarr;
      let results = queryString
        ? DistributionChannelsarr.filter(this.createFilter(queryString))
        : DistributionChannelsarr;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },

    // 总分店
    querySearch3(queryString, cb) {
      let merarr = this.merarr;
      let results = queryString
        ? merarr.filter(this.createFilter(queryString))
        : merarr;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    // 根据一级查2级
    serviceid1(item) {
      this.servicearr2 = [];
      this.changeBDdata.agent2 = "";
      this.changeBDdata.BDname = "";
      getservice({
        type: 2,
        parentid: item.id,
      }).then((res) => {
        // console.log(res);
        for (var i = 0; i < res.data.rows.length; i++) {
          this.servicearr2.push({
            value: res.data.rows[i].agentname,
            id: res.data.rows[i].id,
          });
        }
      });
      this.conditions.agent1Id = item.id;
    },
    // 获取2级
    serviceid2(item) {
      this.changeBDdata.agent2Id = item.id;
      this.changeBDdata.BDname = "";
      // console.log(item);
      this.getBD(item.id);
    },
    BDid1(item) {
      this.changeBDdata.BDid = item.id;
    },
    // 业务经理
    BDname(queryString, cb) {
      let BDarr = this.BDarr;
      let results = queryString
        ? BDarr.filter(this.createFilter(queryString))
        : BDarr;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    createFilter(queryString) {
      return (restaurant) => {
        return (
          restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) !==
          -1
        );
      };
    },
    BDid(item) {
      this.conditions.BDid = item.id;
    },
    serviceid(item) {
      this.conditions.serviceid = item.id;
      this.getBD(item.id);
    },
    // 服务商级别
    servicelevel(val) {
      // console.log(val);
      this.servicearr = [];
      getservice({
        type: val,
      }).then((res) => {
        // console.log(res);
        for (var i = 0; i < res.data.rows.length; i++) {
          this.servicearr.push({
            value: res.data.rows[i].agentname,
            id: res.data.rows[i].id,
          });
        }
      });
    },
    // 获取BD
    getBD(id) {
      this.BDarr = [];
      getBD({ agentid: id }).then((res) => {
        // console.log(res);
        for (var i = 0; i < res.data.rows.length; i++) {
          this.BDarr.push({
            value: res.data.rows[i].name,
            id: res.data.rows[i].id,
          });
        }
      });
    },
    //获取省
    province() {
      arealist({
        level: 1,
      }).then((res) => {
        // console.log(res);
        this.provincearr = res.data;
      });
    },
    //获取市
    city(val) {
      // console.log(val);
      let obj = {};
      obj = this.provincearr.find((item) => {
        //这里的userList就是上面遍历的数据源
        return item.id === val; //筛选出匹配数据
      });
      // console.log(obj);
      // this.conditions.provincecode = obj.code;
      this.conditions.areaId = obj.id;
      this.conditions.city = "";
      this.cityarr = "";
      arealist({
        level: 2,
        parent_id: val,
      }).then((res) => {
        // console.log(res);
        this.cityarr = res.data;
      });
    },
    city2(val) {
      // console.log(val);
      this.conditions.areaId = val;
    },
    // 获取行业
    wx1(val) {
      mcclist({
        level: 1,
      }).then((res) => {
        this.wx1arr = res.data;
      });
    },
    // 行业二级
    wx2fun(val) {
      this.wx2arr = "";
      this.conditions.mccId = val;
      this.conditions.wx1s = "";
      mcclist({
        level: 2,
        parent_id: val,
      }).then((res) => {
        // console.log(res);
        this.wx2arr = res.data;
      });
    },
    // 监听行业2级
    wx3fun(val) {
      this.conditions.mccId = val;
    },
    // 商户列表
    merchantlist(level) {
      // console.log(level, "level");
      let sosolist = {};
      if (level == 1) {
        sosolist = {
          splitMode: this.SplitAccountMode,
          page: this.cur_page,
          size: this.cur_size,
          agent1Id: this.conditions.serviceid,
          bdId: this.conditions.BDid,
          startTime: this.date[0],
          finishTime: this.date[1],
          mccId: this.conditions.mccId,
          areaId: this.conditions.areaId,
          keywords: this.conditions.merchantsno,
          status: this.conditions.merchantsstate,
          tagId: this.tagId,
          status: this.conditions.merchantsstate,
          contactName: this.conditions.contactName,
          payType: this.payType,
          channelType: this.channelType,
          mchId: this.conditions.mchId,
          merchantMode: this.merchantMode,
        };
      } else if (level == 2) {
        sosolist = {
          splitMode: this.SplitAccountMode,
          page: this.cur_page,
          size: this.cur_size,
          agent2Id: this.conditions.serviceid,
          bdId: this.conditions.BDid,
          startTime: this.date[0],
          finishTime: this.date[1],
          mccId: this.conditions.mccId,
          areaId: this.conditions.areaId,
          keywords: this.conditions.merchantsno,
          status: this.conditions.merchantsstate,
          tagId: this.tagId,
          status: this.conditions.merchantsstate,
          contactName: this.conditions.contactName,
          payType: this.payType,
          channelType: this.channelType,
          mchId: this.conditions.mchId,
          merchantMode: this.merchantMode,
        };
      } else {
        sosolist = {
          splitMode: this.SplitAccountMode,
          page: this.cur_page,
          size: this.cur_size,
          bdId: this.conditions.BDid,
          agent2Id: this.conditions.serviceid,
          startTime: this.date[0],
          finishTime: this.date[1],
          mccId: this.conditions.mccId,
          areaId: this.conditions.areaId,
          keywords: this.conditions.merchantsno,
          status: this.conditions.merchantsstate,
          tagId: this.tagId,
          status: this.conditions.merchantsstate,
          contactName: this.conditions.contactName,
          payType: this.payType,
          channelType: this.channelType,
          mchId: this.conditions.mchId,
          merchantMode: this.merchantMode,
        };
      }
      merchantlist(sosolist).then((res) => {
        switch (res.code) {
          case 405:
            sessionStorage.removeItem("token");
            this.$router.push("/login");
            break;
          case 200:
            this.defaulMerchantListData(res);
            this.loading = false;
            break;
          default:
            // console.log("res", res.pageInfo);
            this.$message.error(res.message);
            this.loading = false;
            this.defaulMerchantListData(res);
            break;
        }
      });

      getActiveCount(sosolist).then((res) => {
        // console.log(res);
        this.merchantsinfo = res.data;
      });
    },
    //获取分账通道
    DistributionChannelsList() {
      APIDistributionChannelsList().then((res) => {
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else if (res.code == 200) {
          // console.log("分账通道", res.data);
          this.DistributionChannelsarr = [];
          for (var i = 0; i < res.data.length; i++) {
            this.DistributionChannelsarr.push({
              id: res.data[i].id,
              value: res.data[i].channelname,
              type: res.data[i].paytype,
            });
          }
        } else {
          this.$message.error(res.message);
        }
      });
    },
    //获取交易商户
    allTransactionMerchantlist() {
      APIallTransactionMerchantlist().then((res) => {
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else if (res.code == 200) {
          // console.log("交易商户列表", res.data);
          this.TransactionMerchantarr = [];
          for (var i = 0; i < res.data.length; i++) {
            this.TransactionMerchantarr.push({
              value: res.data[i].tradeMerchantName,
              id: res.data[i].tradeMerchantId,
              No: res.data[i].tradeMerchantNo,
            });
          }
        } else {
          this.$message.error(res.message);
        }
      });
    },
    // 获取总店
    allmerchantlist() {
      allmerchantlist({
        pid: "-1",
      }).then((res) => {
        // console.log(res);
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else if (res.code == 200) {
          // console.log(res);
          this.merarr = [];
          for (var i = 0; i < res.data.rows.length; i++) {
            this.merarr.push({
              value: res.data.rows[i].merchantName,
              id: res.data.rows[i].id,
            });
          }
        } else {
          this.$message.error(res.message);
        }
      });
    },
    // 选取总店
    dianming(val) {
      this.setupshops.pid = val.id;
    },
    //选取分账商户
    dianming2(val) {
      // console.log("分账商户", val);
      //  this.SplitAccount.merchantNo = val.No
      this.SplitAccount.tradeMerchantId = val.id;
    },
    //选取分账通道
    dianming3(val) {
      // console.log("分账通道", val);
      this.SplitAccount.channelId = val.id;
      this.SplitAccount.channelType = val.type;
      this.SplitAccount.channelName = val.value;
    },
    //维度查询标签
    // dimension_menu(v){
    //   this.label_all = []
    //   getDimensionTagList({
    //     roleId: v
    //   }).then(res => {
    //     if(res.code == 405){
    //       sessionStorage. removeItem('token')
    //       this.$router.push('/login');
    //     }else if(res.code == 200){
    //       for(var i=0;i<res.data.length;i++){
    //         this.label_all.push({'value':res.data[i].tagName,'id':res.data[i].tagId})
    //       }
    //     }else{
    //       this.$message.error(res.message);
    //     }
    //   })
    // },
    //标签模糊
    querySearch_tag(queryString, cb) {
      let that = this;
      getDimensionTagList({
        roleId: 5,
        tagwords: this.tagname,
      }).then((res) => {
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          that.$router.push("/login");
        } else if (res.code == 200) {
          that.label_all = [];
          for (var i = 0; i < res.data.length; i++) {
            that.label_all.push({
              value: res.data[i].tagName,
              id: res.data[i].tagId,
            });
          }
          let servicearr = that.label_all;
          let results = queryString
            ? servicearr.filter(that.createFilter(queryString))
            : servicearr;
          // 调用 callback 返回建议列表的数据
          cb(results);
        } else {
          that.$message.error(res.message);
        }
      });
    },
    serviceid_tag(item) {
      // console.log(item);
      this.tagId = item.id;
    },
    // 打开增加门店
    addshop(val, id) {
      this.chengeqx = 0;
      this.visible = true;
      this.shopname = val;
      this.shopid = id;
      this.addmendian = {
        name: "",
        phone: "",
        address: "",
        contact: "",
        contactphone: "",
        mchUniNo: "",
        wxMchId: "",
        wxAppid: "",
        udfType: "",
        udfAccount: "",
        bank: "",
        alias: "",
        wxGoodsTag: "",
        ecnyTermId: "",
      };
    },
    // 增加门店
    addshopfun() {
      // console.log("ss", this.chengeqx);
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      addshop({
        merchantId: this.shopid,
        shopName: this.addmendian.name,
        shopTel: this.addmendian.phone,
        shopAddress: this.addmendian.address,
        managerName: this.addmendian.contact,
        managerMobile: this.addmendian.contactphone,
        terminalNoUni: this.addmendian.bank,
        aliShopId: this.addmendian.aliShopId,
        aliSpmerToken: this.addmendian.aliSpmerToken,
        alias: this.addmendian.alias,
        mchUniNo: this.addmendian.mchUniNo,
        wxMchId: this.addmendian.wxMchId,
        wxAppid: this.addmendian.wxAppid,
        udfType: this.addmendian.udfType,
        udfAccount: this.addmendian.udfAccount,
        canCancelCoupon: this.chengeqx,
        longpayPostId: this.addmendian.longpayPostId,
        longpayPublicKey: this.addmendian.longpayPublicKey,
        wxGoodsTag: this.addmendian.wxGoodsTag,
        ecnyTermId: this.addmendian.ecnyTermId,
        userId: 1,
        instno: sessionStorage.getItem("instNo"),
        key: sessionStorage.getItem("key"),
      }).then((res) => {
        if (res.code == 200) {
          loading.close();
          this.$message({
            message: "新增成功",
            type: "success",
          });
          this.visible = false;
          this.refresh();
        } else {
          this.$message.error(res.message);
          loading.close();
        }
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
        }
      });
    },
    // 停用门店
    blockups(val) {
      var that = this;
      this.$confirm("是否确定停用？如确定，该商户的支付将停用", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          blockup({}, val).then((res) => {
            // console.log(res);
            if (res.code == 405) {
              sessionStorage.removeItem("token");
              this.$router.push("/login");
            } else if (res.code == 200) {
              this.$message({
                message: "已停用",
                type: "success",
              });
              this.refresh();
            } else {
              this.$message.error(res.message);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    // 注销门店
    merchantremove(val) {
      this.$confirm("是否确定注销？如确定，该商户将被移除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          merchantremove({}, val).then((res) => {
            // console.log(res);
            if (res.code == 405) {
              sessionStorage.removeItem("token");
              this.$router.push("/login");
            } else if (res.code == 200) {
              this.$message({
                message: "已注销",
                type: "success",
              });
              this.refresh();
            } else {
              this.$message.error(res.message);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    // 启用商户
    merchantenable(val) {
      merchantenable({}, val).then((res) => {
        // console.log(res);
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else if (res.code == 200) {
          this.$message({
            message: "已启用",
            type: "success",
          });
          this.refresh();
        } else {
          this.$message.error(res.message);
        }
      });
    },
    // 新增门店
    addmerchants() {
      this.$router.push({
        path: "/addmerchants",
        query: {
          // no: val,
        },
      });
    },

    closetab() {
      // console.log(this.tagsList);
      for (var i = 0; i < this.tagsList.length; i++) {
        if (this.tagsList[i].title == "我的商户") {
          this.tagsList.splice(i, 1)[0];
          bus.$emit("tags", this.tagsList);
          this.$router.push("/audit");
        }
      }
    },

    // 打开切换bdbox
    changeBDbtn() {
      this.changeBDdata = {
        agent1: "",
        agent2: "",
        BDname: "",
      };
      if (this.multipleSelection.length > 0) {
        this.changeBD = true;
        getservice({
          type: 1,
        }).then((res) => {
          // console.log(res);
          for (var i = 0; i < res.data.rows.length; i++) {
            this.servicearr1.push({
              value: res.data.rows[i].agentname,
              id: res.data.rows[i].id,
            });
          }
        });
      } else {
        this.$message.error("请选择商户");
      }
    },
    // 确定切换
    changeBDok() {
      let that = this;
      // console.log(this.changeBDdata.BDid)
      this.ids = [];
      for (var item of this.multipleSelection) {
        this.ids.push(item.id);
      }
      if (this.changeBDdata.BDid) {
        axios
          .post(
            process.env.VUE_APP_BASE_URL +
              "/product/v31/api/merchant/transfer/" +
              this.changeBDdata.BDid,
            this.ids,
            {
              headers: {
                "Content-Type": "application/json",
                token: sessionStorage.getItem("token"),
              },
            }
          )
          .then(function (res) {
            // console.log(res);
            if (res.data.code == 405) {
              sessionStorage.removeItem("token");
              that.$router.push("/login");
            } else if (res.data.code == 200) {
              that.$message({
                message: "切换成功",
                type: "success",
              });
              that.refresh();
              that.changeBD = false;
            } else {
              that.$message.error(res.data.message);
            }
          });
      } else {
        this.$message.error("请选择业务经理");
      }
    },
    // 导出商户
    //导出
    merchantexcel() {
      let sosolist = {};
      if (this.conditions.servicelevel == 1) {
        sosolist = {
          agent1Id: this.conditions.serviceid,
          bdId: this.conditions.BDid,
          startTime: this.date[0],
          finishTime: this.date[1],
          mccId: this.conditions.mccId,
          areaId: this.conditions.areaId,
          // cityCode: this.conditions.city,
          // merchantMcc2: this.conditions.wx1s,
          // provinceCode: this.conditions.provincecode,
          keywords: this.conditions.merchantsno,
          status: this.conditions.merchantsstate,
          tagId: this.tagId,
          payType: this.payType,
          channelType: this.channelType,
          mchId: this.conditions.mchId,
          merchantMode: this.merchantMode,
        };
      } else if (this.conditions.servicelevel == 2) {
        sosolist = {
          agent2Id: this.conditions.serviceid,
          bdId: this.conditions.BDid,
          startTime: this.date[0],
          finishTime: this.date[1],
          mccId: this.conditions.mccId,
          areaId: this.conditions.areaId,
          // cityCode: this.conditions.city,
          // merchantMcc2: this.conditions.wx1s,
          // provinceCode: this.conditions.provincecode,
          keywords: this.conditions.merchantsno,
          status: this.conditions.merchantsstate,
          tagId: this.tagId,
          payType: this.payType,
          channelType: this.channelType,
          mchId: this.conditions.mchId,
          merchantMode: this.merchantMode,
        };
      } else {
        sosolist = {
          bdId: this.conditions.BDid,
          agent2Id: this.conditions.serviceid,
          startTime: this.date[0],
          finishTime: this.date[1],
          mccId: this.conditions.mccId,
          areaId: this.conditions.areaId,
          // cityCode: this.conditions.city,
          // merchantMcc2: this.conditions.wx1s,
          // provinceCode: this.conditions.provincecode,
          keywords: this.conditions.merchantsno,
          status: this.conditions.merchantsstate,
          tagId: this.tagId,
          payType: this.payType,
          channelType: this.channelType,
          mchId: this.conditions.mchId,
          merchantMode: this.merchantMode,
        };
      }
      this.exxxx = true;
      let i = 0;
      let time = setInterval(() => {
        if (i == 60) {
          loading.close();
          this.$message.error("请求超时");
          clearInterval(time);
        } else {
          i++;
        }
      }, 1000);
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      myMerchantExcel(sosolist).then((res) => {
        if (res.data.code == 405) {
          clearInterval(time);
          sessionStorage.removeItem("token");
          this.$router.push("/login");
          loading.close();
          this.exxxx = false;
        } else if (res.data.code == 200) {
          clearInterval(time);
          let elink = document.createElement("a");
          elink.download = "我的商户.xls";
          elink.href = res.data.data.replace("http://", "https://");
          elink.click();
          loading.close();
          this.exxxx = false;
        } else {
          clearInterval(time);
          this.$message.error(res.data.message);
          loading.close();
          this.exxxx = false;
        }
      });
    },
    //打开开通分账弹窗
    SplitAccountWindow() {
      if (this.multipleSelection.length > 0) {
        this.SplitAccountState = true;
        this.allTransactionMerchantlist();
        this.DistributionChannelsList();
        // console.log(this.multipleSelection);
      } else {
        this.$message.error("请选择商户");
      }
    },
    // 打开总分店弹窗
    setupshop() {
      if (this.multipleSelection.length > 0) {
        this.visible1 = true;
        this.allmerchantlist();
        // console.log(this.multipleSelection);
      } else {
        this.$message.error("请选择商户");
      }
    },
    //判断是否是是交易商户
    SplitAccountType(labelValue) {
      this.cleanSplitAccountData(labelValue);
    },
    // 判断总店分店
    setupshopstype(e) {
      // console.log(e);
      if (e == "-1") {
        this.setupshops.pid = "-1";
      }
    },
    //关闭配置分账弹窗
    closeSplitAccount() {
      this.SplitAccountState = false;
      this.cleanSplitAccountData();
    },
    //确定分账商户
    splitAccountOk() {
      // console.log("分账传的数据", this.SplitAccount);
      let that = this;
      let idArr = [];
      let NoArr = [];
      for (let item of this.multipleSelection) {
        idArr.push(item.id);
        NoArr.push(item.merchantNo);
      }
      that.SplitAccount.merchantId = idArr.join(",");
      this.SplitAccount.merchantNo = NoArr.join(",");
      APIActivateSplitAccountMerchants({
        tradeMerchantId: this.SplitAccount.tradeMerchantId,
        flag: this.SplitAccount.flag,
        merchantId: this.SplitAccount.merchantId,
        // merchantNo:this.SplitAccount.merchantNo,
        channelId: this.SplitAccount.channelId,
        channelType: this.SplitAccount.channelType,
        channelName: this.SplitAccount.channelName,
      }).then((res) => {
        if (res.code == 200) {
          that.$message({
            message: "开通成功",
            type: "success",
          });
        } else {
          that.$message.error(res.message);
        }

        this.refresh();
        this.closeSplitAccount();
      });
    },

    // 确定总分店
    setupshopok() {
      // console.log(this.setupshops);
      let that = this;
      let dianarr = [];
      let marid = "";
      for (var item of this.multipleSelection) {
        dianarr.push(item.id);
      }
      marid = dianarr.join(",");
      chainopen({
        id: marid,
        openTime: that.setupshops.openTime,
        closeTime: that.setupshops.closeTime,
        limitFee: that.setupshops.lines,
        pid: that.setupshops.pid,
        polling: that.setupshops.polling,
      }).then((res) => {
        if (res.code == 200) {
          that.$message({
            message: "开通成功",
            type: "success",
          });
        } else {
          that.$message.error(res.message);
        }
        this.visible1 = false;
        this.refresh();
        this.setupshops = {
          type: "-1",
          openTime: "",
          closeTime: "",
          permissions: "",
          lines: "",
          pid: "-1",
          polling: "0",
        };
      });
    },
    // 关闭总门店
    chainclose(id) {
      let that = this;
      // console.log(id);
      this.$confirm("是否确定关闭？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          chainopen({
            id: id,
          }).then((res) => {
            if (res.code == 200) {
              that.$message({
                message: "已关闭总分店模式",
                type: "success",
              });
            } else {
              that.$message.error(res.message);
            }
            this.refresh();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
  },
};
</script>
<style scoped>
.title {
  background: #fff;
  padding: 10px 10px;
  font-size: 18px;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
}
.screeningBox {
  width: 100%;
  display: flex;
}
.leftBox,
.rightBox {
  width: 50%;
  padding: 0 15px;
  box-sizing: border-box;
}
.leftBox > .leftitem {
  margin-bottom: 15px;
}
.rightBox > .rightitem {
  margin-bottom: 15px;
}
.merchants {
  width: 30%;
}
.merchants1 {
  width: 30%;
}
.store-detail {
  display: flex;
}
.detail-item {
  flex: 1;
}
.statistical {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #00152a;
  color: #fff;
  padding: 12px;
  box-sizing: border-box;
}
.statistical > .statisticalitem {
  width: 50%;
  text-align: center;
  line-height: 200%;
}
.tableBox {
  margin-top: 20px;
}
.store-input {
  width: 95%;
}
.servicename {
  width: 30%;
}
.BDname {
  width: 30%;
}
.red {
  color: #f9607d;
}
.green {
  color: green;
}
.hui {
  color: darkgray;
}
.blue {
  color: blue;
}
.wid100 {
  width: 100%;
  margin-bottom: 20px;
}
.position {
  position: absolute;
  left: 0;
  top: 25px;
  background: #f9607d;
  color: #fff;
  padding: 0;
  width: 18px;
  height: 18px;
  line-height: 20px;
  box-sizing: border-box;
  border-radius: 3px;
}
.greens {
  background: green;
}
.merchantNameStyle {
  width: 210px;
  padding-left: 20px;
}
</style>